package com.yunshipei.core.utils;

import android.content.Context;

import java.io.IOException;
import java.util.Properties;

public class MimeTypeUtils {

    public static String getMimeType(Context context, String fileName) {
        try {
            Properties properties = new Properties();
            properties.load(context.getApplicationContext().getResources().getAssets().open("mime.properties"));
            int extPos = fileName.lastIndexOf(".");
            if (extPos != -1) {
                String ext = fileName.substring(extPos + 1);
                if ("enc".equals(ext)) {
                    return "text/javascript";
                }
                return properties.getProperty(ext);
            } else {
                return null;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}